package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhAfterFactoryLogin;
import com.ruoyi.zsyh.service.IZsyhAfterFactoryLoginService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 售后厂家账号管理Controller
 * 
 * @author yuexl
 * @date 2022-09-26
 */
@Controller
@RequestMapping("/zsyh/afterFactoryLogin")
public class ZsyhAfterFactoryLoginController extends BaseController
{
    private String prefix = "zsyh/afterFactoryLogin";

    @Autowired
    private IZsyhAfterFactoryLoginService zsyhAfterFactoryLoginService;

    @RequiresPermissions("zsyh:afterFactoryLogin:view")
    @GetMapping()
    public String afterFactoryLogin()
    {
        return prefix + "/afterFactoryLogin";
    }

    /**
     * 查询售后厂家账号管理列表
     */
    @RequiresPermissions("zsyh:afterFactoryLogin:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhAfterFactoryLogin zsyhAfterFactoryLogin)
    {
        startPage();
        List<ZsyhAfterFactoryLogin> list = zsyhAfterFactoryLoginService.selectZsyhAfterFactoryLoginList(zsyhAfterFactoryLogin);
        return getDataTable(list);
    }

    /**
     * 导出售后厂家账号管理列表
     */
    @RequiresPermissions("zsyh:afterFactoryLogin:export")
    @Log(title = "售后厂家账号管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhAfterFactoryLogin zsyhAfterFactoryLogin)
    {
        List<ZsyhAfterFactoryLogin> list = zsyhAfterFactoryLoginService.selectZsyhAfterFactoryLoginList(zsyhAfterFactoryLogin);
        ExcelUtil<ZsyhAfterFactoryLogin> util = new ExcelUtil<ZsyhAfterFactoryLogin>(ZsyhAfterFactoryLogin.class);
        return util.exportExcel(list, "售后厂家账号管理数据");
    }

    /**
     * 新增售后厂家账号管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存售后厂家账号管理
     */
    @RequiresPermissions("zsyh:afterFactoryLogin:add")
    @Log(title = "售后厂家账号管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhAfterFactoryLogin zsyhAfterFactoryLogin)
    {
        return toAjax(zsyhAfterFactoryLoginService.insertZsyhAfterFactoryLogin(zsyhAfterFactoryLogin));
    }

    /**
     * 修改售后厂家账号管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhAfterFactoryLogin zsyhAfterFactoryLogin = zsyhAfterFactoryLoginService.selectZsyhAfterFactoryLoginById(id);
        mmap.put("zsyhAfterFactoryLogin", zsyhAfterFactoryLogin);
        return prefix + "/edit";
    }

    /**
     * 修改保存售后厂家账号管理
     */
    @RequiresPermissions("zsyh:afterFactoryLogin:edit")
    @Log(title = "售后厂家账号管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhAfterFactoryLogin zsyhAfterFactoryLogin)
    {
        return toAjax(zsyhAfterFactoryLoginService.updateZsyhAfterFactoryLogin(zsyhAfterFactoryLogin));
    }

    /**
     * 删除售后厂家账号管理
     */
    @RequiresPermissions("zsyh:afterFactoryLogin:remove")
    @Log(title = "售后厂家账号管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhAfterFactoryLoginService.deleteZsyhAfterFactoryLoginByIds(ids));
    }

    @GetMapping("/resetPwd/{id}")
    public String resetPwd(@PathVariable("id") String id, ModelMap mmap)
    {
        mmap.put("zsyhAfterFactoryLogin", zsyhAfterFactoryLoginService.selectZsyhAfterFactoryLoginById(id));
        return prefix + "/resetPwd";
    }

    @Log(title = "重置密码", businessType = BusinessType.UPDATE)
    @PostMapping("/resetPwd")
    @ResponseBody
    public AjaxResult resetPwdSave(ZsyhAfterFactoryLogin zsyhAfterFactoryLogin)
    {
        zsyhAfterFactoryLogin.setLoginPassword(new Md5Hash(zsyhAfterFactoryLogin.getLoginPassword()).toHex());
        int num = zsyhAfterFactoryLoginService.updateZsyhAfterFactoryLogin(zsyhAfterFactoryLogin);
        return toAjax(num);
    }
}
